with open("ipy.tpr") as f:
    ipy=eval(f.read())
with open("npy.tpr") as f:
    npy=eval(f.read())
def tuplelt(t):
    return ' '.join(t)
def fenge(s):
    lis=[]
    if len(s)==1:
        return ((s,),)
    for i in range(1,len(s)):
        for j in fenge(s[i:]):
            lis.append((s[:i],)+j)
    lis.append((s,))
    return tuple(sorted(lis,key=tuplelt))
def fgshell(s):
    return list(fenge(s))
def crcpinyin(s):
    fgl=fgshell(s)
    l=[]
    for i in fgl:
        correct=True
        for j in i:
            if not(j in ipy):
                correct=False
        if correct:
            l.append(i)
    return l
def crcspinyin(s):
    fgl=fgshell(s)
    l=[]
    for i in fgl:
        correct=True
        for j in i:
            if not(j in npy):
                correct=False
        if correct:
            l.append(i)
    return l
